// pages/order/refund_info/refund_info.js
const app=getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    state:0,//0-未发货理由，1-已收到货物理由
    user_note:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({orderid:options.orderid || ''})
    this.getReason();
  },
  getReason:function(){
    let data={state:this.data.state};
    app.requestJs('order/refundreason', {data}).then((res) => {
      if (res.errcode == 1) {
        let resData=res.data || {};
        this.setData({
          resason:resData.reason,
          reason:resData.reason.length==0?'':resData.reason[0] || ''
        })
      }else app.utilJs.toast({ title: res.message });
    })
  },
  radioChange:function(e){
    let value=e.detail.value;
    this.setData({
      state:value
    })
    this.getReason();
  },
  reasonChange:function(e){
    console.log(e)
    let value=e.detail.value;
    this.setData({
      reason:value
    })
  },
  orderStateBtn:function(){//订单聚合操作
    let orderid=this.data.orderid;
    let user_note=this.data.reason+'  '+this.data.user_note;
    let data={token:app.globalData.token,orderid,orderstatus:4,user_note}
    app.requestJs("order/orderjuhehander",{data}).then((res) => {
      if (res.errcode == 1) {
        app.utilJs.toast({ title: res.message,icon:'success'});
        const eventChannel = this.getOpenerEventChannel()
        eventChannel.emit('updateData', {data: 'test'});
        setTimeout(() => {
          wx.navigateBack({
            delta:1,
          })
        },500);
      } else {
        app.utilJs.toast({ title: res.message });
      }
    })
  },
  binduser_note:function(e){
    let value=e.detail.value;
    this.setData({
      user_note:value
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})